#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef pair<int, pi> piii;
const int N = 1010, M = 200010;
int n, m, S, T, K;
int h[N], rh[N], e[M], w[N], ne[M], idx;
int dist[N], cnt[N];
bool st[N];
void add(int h[], int a, int b, int c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}

void dijkstra() {
  priority_queue<pi, vector<pi>, greater<pi>> heap;
  heap.emplace(0, T);

  memset(dist, 0x3f, sizeof dist);
  dist[T] = 0;
  while (heap.size()) {
    auto [d, v] = heap.top();
    heap.pop();
    if (st[v]) continue;
    st[v] = true;

    for (int i = rh[v]; ~i; i = ne[i]) {
      int j = e[i];
      if (dist[j] > dist[v] + w[i]) {
        dist[j] = dist[v] + w[i];
        heap.emplace(dist[i], j);
      }
    }
  }
}

int astar() {
  priority_queue<piii, vector<piii>, greater<piii>> heap;
  heap.push({dist[5], {0, S}});
  while (heap.size()) {
    auto t = heap.top();
    heap.pop();
    int ver = t.second.second, d = t.second.first;
    cnt[ver]++;
    if (cnt[T] == K) return d;

    for (int i = h[ver]; ~i; i = ne[i]) {
      int j = e[i];
      if (cnt[j] < K) heap.push({d + w[i] + dist[j], {d + w[i], j}});
    }
  }
  return -1;
}

int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  memset(rh, -1, sizeof rh);

  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    add(h, a, b, c), add(rh, b, a, c);
  }
  cin >> S >> T >> K;
  if (S == T) K++;

  dijkstra();
  cout << astar() << endl;
}
